package com.xinyue.game.client.command;

import com.xinyue.game.client.network.GameClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.shell.ExitRequest;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.commands.Quit;

/**
 * 重写spring shell自带的退出命令
 *
 * @Author 王广帅
 * @Date 2021/1/29 0:33
 */
@ShellComponent
public class ExitCommand implements Quit.Command {
    private Logger logger = LoggerFactory.getLogger(ExitCommand.class);

    @ShellMethod("退出当前客户端")
    public void quit() {
        GameClient gameClient = GameClientNetworkCommand.gameClient;
        if (gameClient != null) {

            gameClient.disconnect();

        }
        logger.info("正在退出当前客户端....");
        throw new ExitRequest();
    }

    @ShellMethod("退出当前客户端")
    public void exit() {
        quit();
    }
}
